package com.bw.biz.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bw.biz.pojo.TbProduct;
import com.bw.biz.mapper.TbProductMapper;
import com.bw.biz.service.TbProductService;
import com.bw.core.result.ResponseResult;
import com.bw.core.utils.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 产品表 服务实现类
 * </p>
 *
 * @author lv
 * @since 2021-03-23
 */
@Service
public class TbProductServiceImpl extends ServiceImpl<TbProductMapper, TbProduct> implements TbProductService {
    @Autowired
    private TbProductMapper mapper;

    @Override
    public ResponseResult productList() {
        QueryWrapper<TbProduct> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete",0);
        List<TbProduct> tbProducts = mapper.selectList(wrapper);
        return ResponseResult.success(tbProducts);
    }

    //根据商品名称进行查询
    @Override
    public ResponseResult findProductByName(String name) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("product_name",name);
        TbProduct product = mapper.selectByMap(map).get(0);
        if (StringUtils.isEmpty(product.getProductName())){
            return ResponseResult.error(500,"请刷新重试");
        }
        return ResponseResult.success(product);
    }
}